package ch.bfh.abcmmh.view.frame.subpanels;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;

import javax.swing.JLabel;
import javax.swing.JPanel;

import ch.bfh.abcmmh.view.interfaces.TSSwingObjects;

public class GrassPanel extends JPanel implements TSSwingObjects {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public GrassPanel() {
		Color c = new Color(0, 190, 0);
		this.setBackground(c);
		this.setLayout(null);
		
		this.putSomeTreesOnTheGrass();
		
		
		repaint();
	}

	private void putSomeTreesOnTheGrass(){
	
		int x = 5, y = 5;
		while (x<1400) {
			makeTree(x, y, (int)(Math.random()*40)+4);
			y= (int)(Math.random()*30);
			x+= (int)(Math.random()*160);
		}
		
		
	}
	
	
	private void makeTree(int x, int y, int diameter) {
		RoundTree rt1 = new RoundTree(diameter);
		rt1.setLocation(x, y);
		add(rt1);
	}
	
	@Override
	public void repaintSubsandMe() {

		repaint();
	}

	private class RoundTree extends JLabel{
		
		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;
		int diameter;
		private RoundTree(int diameter){
			this.diameter = diameter;
			Dimension dimension = new Dimension(diameter, diameter);
			this.setPreferredSize(dimension);
			this.setSize(dimension);
			this.setOpaque(true);
			this.setVisible(true);
		}
		
		public void paintComponent(Graphics g){
			Graphics2D g2 = (Graphics2D) g;
			g2.setColor(new Color(0, 80, 0));
			g2.fillOval(0, 0, this.diameter, this.diameter);

		}
	}
}
